const modules = import.meta.glob(["pkgs/**/**/*.vue"], {
  eager: true,
});
import _ from "lodash";
let cmpntPrefix = "x-";
const cmpnts = {};
for (const fullPath in modules) {
  const lastName = _.last(fullPath.split("/"));
  const fileName = cmpntPrefix + lastName;
  const componentName = _.kebabCase(fileName.replace(/\.vue$/, "")); //cmpntBar->cmpnt-bar
  const component = modules[fullPath].default;
  cmpnts[componentName] = component;
}
console.log("cmpnts:", cmpnts, modules);
// 定义 install 方法，接收 Vue 作为参数。如果使用 use 注册插件，则所有的组件都将被注册
const install = function (app) {
  // 判断是否安装
  if (install.installed) return;
  install.installed = true;
  for (const name in cmpnts) {
    app.component(name, cmpnts[name]);
  }
};

export default {
  install,
};
